#!/bin/bash

# rem Artifactory
. ../../../../3rdparty/artifactory/protoc.sh


compiler_dir="../../../../3rdparty/artifactory/protoc"
compiler=$compiler_dir/protoc

# Running on Mac
if [ `uname` == 'Darwin' ]; then
   compiler_dir="../../../../3rdparty/artifactory/protoc"
   compiler=$compiler_dir/protoc
fi

LD_LIBRARY_PATH=$compiler_dir
export LD_LIBRARY_PATH

root_dir=.
src_dir=$root_dir
output_dir=$root_dir/Output

extension=*.proto

option_postfix=_out
option_cpp=cpp
option_js=js
option_python=python
option_csharp=csharp

if [ ! -d $output_dir ]; then
   mkdir $output_dir
fi

compile ()
{
    option=$1
    output=$2
    src=$3
    
    rm -rf $output
    mkdir $output

    files=`find $src -name \$extension` 
    for file in $files
    do
        $compiler --$option$option_postfix=$output $file
    done
}

echo Generate $option_cpp header and source files
compile $option_cpp $output_dir/$option_cpp $src_dir

echo Generate $option_js source files
compile $option_js $output_dir/$option_js $src_dir

echo Generate $option_python source files
compile $option_python $output_dir/$option_python $src_dir

echo Generate $option_csharp source files
compile $option_csharp $output_dir/$option_csharp $src_dir
